package no.ntnu.idi.deid.decision.validators.findPhrase.helpers;

import no.ntnu.idi.deid.documentunits.Phrase;
import no.ntnu.idi.deid.documentunits.Sentence;

public class ExactDistance {

	
	private ExactDistance() {
		
	}
		
	public static Phrase findPhrase(Sentence sentence, String phrase) {
		if(sentence.getStripped().toLowerCase().contains(phrase.toLowerCase())) {
			String[] resultString = phrase.split(" ");
			int index = 0;
			while(!(resultString[0].toLowerCase()).equals(sentence.get(index).getStripped().toLowerCase())) {
				index++;
				if(index > sentence.size()) {
					return null;
				}
			}
			Phrase returnPhrase = new Phrase();
			for(int i = index; i < index+resultString.length; i++) {
				returnPhrase.add(sentence.get(i));
			}
			return returnPhrase;
			
		}
		else {
			return null;
		}
	}

}
